<?php /*
	
*/ ?>
<?php include("system/config.inc.php");
$donotinclude = 1;
if(!isset($_SESSION['adminuserid']))
{
	header("location:index.php?msg=logfirst");
	die();
}

// INSERT into database.
if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")
	{
				
				$orderid = mysql_real_escape_string($_REQUEST['orderid']);
				$custemail = mysql_real_escape_string($_REQUEST['custemail']);
				$prid = mysql_real_escape_string($_REQUEST['prid']);
				//$symright = $_REQUEST['symright'];
				$status = mysql_real_escape_string($_REQUEST['status']);
				$comments=mysql_real_escape_string($_REQUEST['comments']);
				$insert = "INSERT INTO `tblram`
				(`intorderid` , `varcustemail` , `intproid`, `intstatus` , `ttdate`,`txtcomments`)
				VALUES ('$orderid', '$custemail', '$prid', '$status', NOW(),'$comments')";
				
				$sql=$obj_db->insert($insert);
				
				header("location:ram.php?msg=add");
				die();
	}	

// UPDATE the record
$intorderid = "";
$varcustemail = "";
$intproid = "";
$intstatus = "";
$txtcomments="";
$action=1;

if((isset($_REQUEST['a']) && trim($_REQUEST['a'])==2) && (!(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")))
{
 	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid'])!="")
 	{
		$screen_id =  mysql_real_escape_string($_REQUEST['intid']);
		$sql = "select * from tblram where intid ='$screen_id'";
		$result = $obj_db->select($sql);
		
		if(count($result)<=0)
		{
			echo " No Record Found!<br>";
			die();
		}
		
		if($result)
		{
			foreach($result as $row)
			{
				$intorderid = stripslashes($row['intorderid']);	   
		   		$varcustemail = stripslashes($row['varcustemail']);
				$intproid = stripslashes($row['intproid']);
				$intstatus = stripslashes($row['intstatus']);
				$txtcomments = stripslashes($row['txtcomments']);
				$action=2;
			}
		}
		if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Update")
		{
				$orderid = mysql_real_escape_string($_REQUEST['orderid']);
				$custemail = mysql_real_escape_string($_REQUEST['custemail']);
				$prid = mysql_real_escape_string($_REQUEST['prid']);
				$status = mysql_real_escape_string($_REQUEST['status']);
				$comments=mysql_real_escape_string($_REQUEST['comments']);
			
			$sql_upd ="UPDATE tblram SET  
						`intorderid` = '$orderid',
						`varcustemail` = '$custemail',						 
						`intproid` = '$prid',
						`intstatus` = '$status',
						`txtcomments`='$comments'
						where intid ='$screen_id'";		
			$result = $obj_db->edit($sql_upd);
			$action=1;
			header("location:ram.php?msg=edit");
			die();
		}
	}

}

//DELETE record from database
if(isset($_REQUEST['a']) && trim($_REQUEST['a'])==3)
{
	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid']!=""))
	{	
		$id =  mysql_real_escape_string($_REQUEST['intid']);
		$sql= "DELETE FROM `tblram` WHERE `intid` ='$id'";
		$query1 = mysql_query($sql);
		
		header("location:ram.php?msg=del");
		die();
	}
}



if(isset($_REQUEST['statusch']) && $_REQUEST['statusch']!="")
{
	$stid=$_REQUEST['statusch'];
	$stid=explode("||",$stid);
	
	$upd="update tblram set intstatus='".$stid[0]."' where intid='".$stid[1]."'";
	$sqlupd=$obj_db->edit($upd);
	
	header("location:ram.php?msg=status");
		die();
}


?>
<?php include("inc/header.php");?>
<body>
<script language="javascript" src="js/currency.js"></script>
<script language="javascript">
// JavaScript Document
function check()
{
	var cond=true;
	if(document.currency.orderid.value.length==0)
	{
		alert("Please Enter Order ID.");
		if(cond==true)
		{
			document.currency.orderid.focus();
		}
		cond=false;
		return false;
	}	
	if(document.currency.custemail.value==0)
	{
		alert("Please Enter Customer Email.");
		if(cond==true)
		{
			document.currency.custemail.focus();
		}
		cond=false;
		return false;
	}
	if(document.currency.prid.value.length==0)
	{
		alert("Please Enter Product Id.");
		if(cond==true)
		{
			document.currency.prid.focus();
		}
		cond=false;
		return false;
	}	
	
	if(document.currency.status.value==0)
	{
		alert("Please select Status.");
		if(cond==true)
		{
			document.currency.status.focus();
		}
		cond=false;
		return false;
	}	
	
	if(!IsNumeric(document.currency.orderid.value))
	{
		alert("Please Enter Numeric Values for Order ID.");
		if(condition==true)
		{
			document.currency.orderid.focus();
		}
		condition=false;
		return false;
			
	}
}	

//  only insert integer no in Age field.
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}
</script>
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" class="middlebackground">
  <tr>
    <td colspan="3" valign="top" align="center"><?php include(INC."top.inc.php");?></td>
  </tr>
  <tr>
    <td width="2%">&nbsp;</td>
    <td width="95%"><?php   
   if(isset($_REQUEST['script']))
	{
	if(trim($_REQUEST['script'])=='addrma' || trim($_REQUEST['script'])=='editrma')
	{
	?>
		<form action="" method="post" enctype="multipart/form-data" name="currency">
	
      <table border="0" align="center" cellpadding="2" cellspacing="2" class="border">
        <tr class="bg1">
          <td colspan="5" align="center"><strong>
            <?php if($_REQUEST['script']=='addrma'){echo "Add RMA ...";}
			if($_REQUEST['script']=='editrma'){echo "Edit RMA...";}?>
          </strong></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="left">&nbsp;</td>
          <td>&nbsp;</td>
          <td align="right">(* All fields are Required)</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td width="2%">&nbsp;</td>
          <td width="30%" align="left" class="sltimg">*Order ID </td>
          <td width="3%" align="left">:</td>
          <td width="56%" align="left"><label>
            <input name="orderid" type="text" id="orderid" value="<?php echo stripslashes($intorderid);?>" />
          </label></td>
          <td width="9%">&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="left" class="sltimg">*Customer Email </td>
          <td align="left">:</td>
          <td align="left"><input name="custemail" type="text" id="custemail" value="<?php echo stripslashes($varcustemail);?>" /></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="left" class="sltimg">*Product ID </td>
          <td align="left">:</td>
          <td align="left"><input name="prid" type="text" id="prid" value="<?php echo stripslashes($intproid);?>" /></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="left" class="sltimg">Status </td>
          <td align="left">:</td>
          <td align="left"><select name="status">
		  <option value="0">Select</option>
		  <option value="1" <?php if($intstatus==1){echo "selected";}?>>Get Call</option>
		  <option value="2" <?php if($intstatus==2){echo "selected";}?>>Issue Fixed</option>
		  <option value="3" <?php if($intstatus==3){echo "selected";}?>>Product Recieved Back</option>
		  <option value="4" <?php if($intstatus==4){echo "selected";}?>>Money refundable</option>
          </select>          </td>
          <td>&nbsp;</td>
        </tr>

        <tr>
          <td align="left">&nbsp;</td>
          <td align="left" valign="top">Comments</td>
          <td align="left" valign="top">:</td>
          <td align="left"><textarea name="comments" cols="30" rows="4" id="comments"><?php echo stripslashes($txtcomments);?></textarea></td>
          <td align="left">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="5" align="left">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="5" align="center"><input name="Submit" type="submit" class="btn" id="Submit" value="<?php echo ($action==2) ? "Update":"Submit"; ?>" onClick="return check();"/></td>
        </tr>
        <tr>
          <td colspan="5" align="center">&nbsp;</td>
        </tr>
      </table>
		</form>
    <?php
	}
}
else
{
?>
<br />
		<br />
		<table border="0" align="center" cellpadding="2" cellspacing="2" class="border">
          <tr class="bg1">
            <td colspan="7" align="left"><strong >RMA List... </strong>&nbsp;&nbsp;</td>
            <td align="center"><a href="ram.php?script=addrma" class="aa">[NEW]</a></td>
          </tr>
          <tr align="center" class="tblbg3">
            <td class="tblbg3">Order id</td>
            <td class="tblbg3">Customer Email </td>
            <td class="tblbg3">Product ID </td>
			<td class="tblbg3">Date Add </td>
			<td class="tblbg3">Status</td>
			<td class="tblbg3">Change Status</td>
			<td class="tblbg3">Edit</td>
            <td>Delete</td>
          </tr>
          <?php
	  /**************************************
		PAGING CODE START
		**************************************/
		//$rowperpage=23;
		$tablename="tblram";
		$per_page_keywords= "";
		$per_page_sorts="";
		include("system/paging.inc.php");

		/**************************************
		PAGING CODE ENDING
		**************************************/
   		$sql="select * from tblram Limit ".($page_no*$row_per_page).",".$row_per_page;
		$result=$obj_db->select($sql);
  		if($result)
		{
   		for($i=0;$i<count($result);$i++)
   		{
            $id=$result[$i]['intid'];
			//$imagepath = "../images/manuf/";
			//$limit=$result[$i]['varimagepath'];
			//$imagename = $imagepath.$limit;
			?>
			<form method="post" name="<?=$id;?>">
          <tr class="<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>" onMouseOver="this.className='Hrhover';"  onMouseOut="this.className='<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>';">
            <td align="center"><?php echo stripslashes($result[$i]['intorderid']);?></td>
            <td align="center"><?php echo stripslashes($result[$i]['varcustemail']);?></td>
            <td align="center"><?php echo stripslashes($result[$i]['intproid']);?></td>
			<td align="center"><?php echo stripslashes($result[$i]['ttdate']);?></td>
			<td align="center">
			<?php 
			$stat=$result[$i]['intstatus'];
			if($stat==1)
			{
			echo "Get Call";
			}
			if($stat==2)
			{
			echo "Issue Fixed";
			}
			if($stat==3)
			{
			echo "Product Recieved Back";
			}
			if($stat==4)
			{
			echo "Money refundable";
			}
			
			?></td>
			<td align="center"><select name="statusch" onChange="this.form.submit();">
              <option value="0">Select</option>
              <option value="1||<?php echo stripslashes($id);?>">Get Call</option>
              <option value="2||<?php echo stripslashes($id);?>">Issue Fixed</option>
              <option value="3||<?php echo stripslashes($id);?>">Product Recieved Back</option>
              <option value="4||<?php echo stripslashes($id);?>">Money refundable</option>
            </select></td>
			<td align="center"><a class="link" Title="Click here to Edit" href="ram.php?script=editrma&amp;a=2&amp;intid=<?php echo $result[$i]['intid']; ?>"><img src="images/edit.bmp" border="0"/></a></td>
            <td align="center"><a Title="Click here to Delete" href="ram.php?a=3&amp;intid=<?php echo $result[$i]['intid']; ?>" onClick="return confirm('Are you sure to delete this record?');"><img src="images/delete.bmp" border="0"/></a></td>
          </tr>
		  </form>
          <?php }}?>
          <tr>
            <td colspan="7" align="center"><?php
pagindet_atbotttom_page($div_page_no,$page_no,$req_querystr,$total_db_rec,$row_per_page);
?></td>
          </tr>
        </table>
		<?php }?>
   </td>
    <td width="3%">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3"><?php include("inc/bottom.php");?></td>
  </tr>
</table>


